<template>
    <!-- <view class="reg" @click="submit">注册</view> -->
    <u-button class="reg" @click="sunmit" text="注册"></u-button>

</template>

<script>
import { get_reg } from "../../api/api"
export default {
    data() {
        return {

        }
    },
    props: ['name', 'password', 'verification'],
    methods: {

        sunmit() {
            let { name, password, verification } = this
            console.log(name)
            if (!/^1[3-9]\d{9}$/.test(name)) {
                // this.$toast('手机号码格式错误');
                console.log("手机号码格式错误")
                return;
            }
            if (!/^\d{6}$/.test(verification)) {
                // this.$toast('验证码格式错误');
                console.log("验证码格式错误")
                return;
            }
            if (!/^\w{6,12}$/.test(password)) {
                // this.$toast('密码格式错误');
                console.log("密码格式错误")
                return;
            }
            get_reg({ username: name, vercode: verification, password: password }).then(res => {
                console.log(res)
                let { token, tokenExpired, uid, userInfo } = res
                if (res.code == 0) {
                    uni.setStorageSync('token', token)
                    uni.setStorageSync('tokenExpired', tokenExpired)
                    uni.setStorageSync('uid', uid)
                    uni.setStorageSync('userInfo', userInfo)
                    setTimeout(function () {
                        uni.navigateTo({
                            url: "/pages/login/login",
                        });
                    }, 20)
                }
            })
        }
    },
}
</script>

<style lang="scss" scoped>

</style>